package org.geektimes.injection.component;

import org.geektimes.injection.stream.ResponseHandlerConsumer;

import java.lang.reflect.Method;
import java.util.Set;

/**
 * 处理方法信息类
 *
 * @since 1.0
 */
public class ControllerComponentBean implements ControllerComponent {

    private final String requestPath;

    private final Method handlerMethod;

    private final Set<String> supportedHttpMethods;
    
    private ResponseHandlerConsumer<Object> responseHandler;
    
    private Object controller;

    public ControllerComponentBean(String requestPath, Method handlerMethod, Set<String> supportedHttpMethods) {
        this.requestPath = requestPath;
        this.handlerMethod = handlerMethod;
        this.supportedHttpMethods = supportedHttpMethods;
    }
    
    public ControllerComponentBean(String requestPath, 
                                   Method handlerMethod, 
                                   Set<String> supportedHttpMethods, 
                                   ResponseHandlerConsumer<Object> responseHandler) {
        this.requestPath = requestPath;
        this.handlerMethod = handlerMethod;
        this.supportedHttpMethods = supportedHttpMethods;
        this.responseHandler = responseHandler;
    }

    public ControllerComponentBean(String requestPath, 
                                   Method handlerMethod, 
                                   Set<String> supportedHttpMethods, 
                                   ResponseHandlerConsumer<Object> responseHandler,
                                   Object controller) {
        this.requestPath = requestPath;
        this.handlerMethod = handlerMethod;
        this.supportedHttpMethods = supportedHttpMethods;
        this.responseHandler = responseHandler;
        this.controller = controller;
    }

    @Override
    public String getRequestPath() {
        return requestPath;
    }

    @Override
    public Method getHandlerMethod() {
        return handlerMethod;
    }

    @Override
    public Set<String> getSupportedHttpMethods() {
        return supportedHttpMethods;
    }

    @Override
    public ResponseHandlerConsumer<Object> getResponseHandler() {
        return responseHandler;
    }

    /**
     * 获取组件对象
     *
     * @return
     */
    @Override
    public Object getBean() {
        return controller;
    }
}
